<template>
  <el-container style="height: 100vh" class="index-con">
      <el-aside :class="showclass">
        <!-- :default-active="$route.path" -->
        <el-menu default-active="2" :collapse="collapsed" collapse-transition router class="el-menu-vertical-demo" background-color="#545c64" text-color="#d3d9e0" active-text-color="#ffd04b">
            <div class="logobox">
              <img class="logoimg" src="../assets/img/logo2.png" alt="">
            </div>
            <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
              <template slot="title">
                  <i class="iconfont" :class="menu.icon"></i>
                  <span>{{menu.menuname}}</span>
              </template>
              <el-menu-item-group>
                  <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
                  <i class="iconfont" :class="chmenu.icon"></i>
                  <span>{{chmenu.menuname}}</span>
                  </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
        </el-menu>
      </el-aside>
      <el-container class="main-con">
        <el-header class="index-header">
            <navcon></navcon>
        </el-header>
        <el-main clss="index-main">
            <router-view></router-view>
        </el-main>
    </el-container>
  </el-container>
</template>

<script>
import navcon from '../components/navcon.vue'
export default {
    
    data(){
        return{
            showclass:'asideshow',
            collapsed: false,
            allmenu: [],
            userStatus:2,
        }
    },
    components:{
        navcon,
    },
    // 创建完毕状态(里面是操作)
  created() {
    // 获取图形验证码
    let res = {
      success: true,
      //普通用户
      data0: [
        {
          menuid: 1,
          icon: 'li-icon-xiangmuguanli',
          menuname: '个人中心',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 11,
              icon: 'icon-cat-skuQuery',
              menuname: '基础信息',
              hasThird: 'N',
              url: 'personalInfo/basicInfo',
              menus: null
            },
            {
                menuid:12,
                icon:'li-icon-dingdanguanli',
                menuname:'详细信息',
                hasThird:'N',
                url:'personalInfo/detailedInfo',
                menus:null
            }
          ]
        },
      ],
      //管理员
      data1:[
        {
          menuid: 1,
          icon: 'li-icon-xiangmuguanli',
          menuname: '个人中心',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 11,
              icon: 'icon-cat-skuQuery',
              menuname: '基础信息',
              hasThird: 'N',
              url: 'personalInfo/basicInfo',
              menus: null
            },
            {
                menuid:12,
                icon:'li-icon-dingdanguanli',
                menuname:'详细信息',
                hasThird:'N',
                url:'personalInfo/detailedInfo',
                menus:null
            }
          ]
        },
        {
          menuid: 2,
          icon: 'li-icon-dingdanguanli',
          menuname: '用户列表',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 21,
              icon: 'icon-order-manage',
              menuname: '列表展示',
              hasThird: 'N',
              url: 'userList/listShow',
              menus: null
            },
            {
              menuid: 22,
              icon: 'icon-order-manage',
              menuname: '标签查询',
              hasThird: 'N',
              url: 'userList/tagSearching',
              menus: null
            }
          ]
        },
        {
          menuid: 3,
          icon: 'li-icon-xitongguanli',
          menuname: '画像展示',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 31,
              icon: 'icon-cus-manage',
              menuname: '个人用户画像展示',
              hasThird: 'N',
              url: 'portraitShow/personalPortrait',
              menus: null
            },
            {
              menuid: 32,
              icon: 'icon-cms-manage',
              menuname: '群体画像展示',
              hasThird: 'N',
              url: 'portraitShow/groupPortrait',
              menus: null
            }
          ]
        },
      ],
      //超级管理员
      data2:[
        {
          menuid: 1,
          icon: 'li-icon-xiangmuguanli',
          menuname: '个人中心',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 11,
              icon: 'icon-cat-skuQuery',
              menuname: '基础信息',
              hasThird: 'N',
              url: 'personalInfo/basicInfo',
              menus: null
            },
            {
                menuid:12,
                icon:'li-icon-dingdanguanli',
                menuname:'详细信息',
                hasThird:'N',
                url:'personalInfo/detailedInfo',
                menus:null
            }
          ]
        },
        {
          menuid: 2,
          icon: 'li-icon-dingdanguanli',
          menuname: '用户列表',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 21,
              icon: 'icon-order-manage',
              menuname: '列表展示',
              hasThird: 'N',
              url: 'userList/listShow',
              menus: null
            },
            {
              menuid: 22,
              icon: 'icon-order-manage',
              menuname: '标签查询',
              hasThird: 'N',
              url: 'userList/tagSearching',
              menus: null
            }
          ]
        },
        {
          menuid: 3,
          icon: 'li-icon-xitongguanli',
          menuname: '画像展示',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 31,
              icon: 'icon-cus-manage',
              menuname: '个人用户画像展示',
              hasThird: 'N',
              url: 'portraitShow/personalPortrait',
              menus: null
            },
            {
              menuid: 32,
              icon: 'icon-cms-manage',
              menuname: '群体画像展示',
              hasThird: 'N',
              url: 'portraitShow/groupPortrait',
              menus: null
            }
          ]
        },
        {
          menuid: 4,
          icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
          menuname: '权限管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 41,
              icon: 'icon-provider-manage',
              menuname: '权限管理',
              hasThird: 'N',
              url: 'authorizationManage/auManage',
              menus: null
            },
          ]
        },
      ],
      msg: 'success'
    }
    var temp=localStorage.getItem('username')
    this.$axios.get('/api/user/finduser',{
            params:{
                param_name:'username',
                param:temp
            }
        }).then(res=>{
            console.log(res)
            localStorage.setItem('username',res.data.username)
            localStorage.setItem('password',res.data.password)
            localStorage.setItem('mail',res.data.mail)
            localStorage.setItem('phonenumber',res.data.phonenumber)
            localStorage.setItem('status',res.data.status)
        })
     var temp=localStorage.getItem('status')
    if(temp==0){
      this.allmenu = res.data0
    }else if(temp==1){
      this.allmenu = res.data1
    }else if(temp==2){
      this.allmenu = res.data2
    }else{
      this.allmenu = res.data2
    }
    
    
    // menu(localStorage.getItem('logintoken'))
    //   .then(res => {
    //     console.log(JSON.stringify(res))
    //     if (res.success) {
    //       this.allmenu = res.data
    //     } else {
    //       this.$message.error(res.msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })

    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
    this.$root.Bus.$on('toggle', value => {
      if (value) {
        this.showclass = 'asideshow'
      } else {
        setTimeout(() => {
          this.showclass = 'aside'
        }, 300)
      }
    })
  },
  beforeUpdate() {},
  // 挂载前状态(里面是操作)
  beforeMount() {
    // 弹出登录成功
    this.$message({
      message: '登录成功',
      type: 'success'
    })
  }
}
</script>

<style>
.index-con {
  height: 100%;
  width: 100%;
  box-sizing: border-box;
}

.aside {
  width: 64px !important;
  height: 100%;
  background-color: #545c64;
  margin: 0px;
}
.asideshow {
  width: 240px !important;
  height: 100%;
  background-color: #545c64;
  margin: 0px;
}
.index-header,
.index-main {
  padding: 0px;
  border-left: 2px solid #333;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #1f2d3d !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  height: 40px;
}
</style>